<template>
  <el-breadcrumb :separator-icon="ArrowRight">
    <el-breadcrumb-item :to="{ path: '/' }">Home</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
  </el-breadcrumb>

  <el-card class="box-card">
    <el-row>
      <el-col :span="8">
        <el-input placeholder="请输入要搜索的订单ID" clearable>
          <template #append>
            <el-button :icon="Search"/>
          </template>
        </el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-table show-overflow-tooltip :data="orderTable.data">
        <el-table-column label="订单用户" prop="user"></el-table-column>
        <el-table-column label="订单价格" prop="price"></el-table-column>
        <el-table-column label="订单数量" prop="number"></el-table-column>
        <el-table-column label="是否支付" prop="pay_status">
          <template #default="scope">
            <el-tag v-if="scope.row.pay_status===1" type="success">已支付</el-tag>
            <el-tag v-else type="danger">未支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">
          <template #default="scope">
            <el-tag v-if="scope.row.is_send===1" type="success">已发货</el-tag>
            <el-tag v-else type="danger">未发货</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="primary" size="small" @click="showExpress(scope.row.id)">查看物流</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
  </el-card>

  <el-dialog title="物流信息" v-model="expressDialogVisible" width="50%">
    <el-timeline style="max-width: 600px">
      <el-timeline-item
          v-for="(exp, index) in expressInfo.data"
          :key="index"
          :timestamp="exp.update_time"
      >
        {{ exp.content }}
      </el-timeline-item>
    </el-timeline>
  </el-dialog>
</template>

<script setup>
import {ArrowRight, Search} from "@element-plus/icons-vue";
import {ref, reactive, onMounted} from "vue";
import api from "@/api";

const orderTable = reactive({
  data: []
})
const expressDialogVisible = ref(false)
let expressInfo = reactive({
  data: []
})


onMounted(() => {
  getOrderList()
})
// 获取订单列表
const getOrderList = () => {
  api.get_orders().then(res => {
    orderTable.data = res.data.data
  })
}
//查看物流
const showExpress = (id) => {
  expressDialogVisible.value = true
  api.get_express(id).then(res => {
    expressInfo.data = res.data.data
  })
}
</script>

<style scoped>
.box-card {
  margin-top: 20px
}
</style>